﻿using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using SmartParing.IService;
using SmartParking.Entities;

namespace SmartParking.Service
{
    public class RoleService : BaseService, IRoleService
    {
        public RoleService(DbContext context)
            : base(context)
        {
            
        }
        public bool CheckRoleName(string roleName, int roleId)
        {
            return this.Query<SysRole>(r =>
                                        r.RoleName == roleName &&
                                        r.RoleId != roleId)
                .Count() > 0;
        }

        public IEnumerable<SysRole> GetRoles(string key)
        {
            return this.Set<SysRole>().Include(r=>r.Users).Include(r=>r.Menus).Where(m =>

                string.IsNullOrEmpty(key) ||

                m.RoleName.Contains(key) ||

                m.RoleDesc.Contains(key) 
            );
        }
    }
}
